//
//  FirstViewController.m
//  League
//
//  Created by 博宇 李 on 2018/1/18.
//  Copyright © 2018年 ciyuanjuzhen. All rights reserved.
//

#import "FirstViewController.h"
#import "LoginViewController.h"
#import "FirHeadView.h"
#import "JKBannarView.h"
#import "UILabel+extension.h"
#import "FMLinkLabel.h"
#import "UILabel+YBAttributeTextTapAction.h"
#import "EventGroupListViewController.h"
#import "UserInfomation.h"
#import "HomePageModel.h"
#import "PowerMoveController.h"

#import <objc/runtime.h>
#import <objc/message.h>

#define kBgColor [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1.0]
#define kBannerTopSpace 10
#define kBannerHeight kScreenWidth-20
#define kUserNameLabeHeight 50
#define kUserInfoLabeHeight 30
#define kCellBtnHeight 60
#define kCellTitleLabHeight 35
#define kCellGroupTitleLabHeight 50
#define kCellMatchesAttendTitleLabHeight 50
#define kFontSize 15

#define kTitleFontSize 13

#define kNameStr @"PC gamers"
#define kText @"could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available"

@interface FirstViewController ()<UITableViewDelegate , UITableViewDataSource,UITabBarDelegate,UITabBarControllerDelegate>
{
    NSBundle *bundle;
    CGFloat descriptionWidth;
}
@property (strong, nonatomic) FirHeadView *headView;
@property(strong , nonatomic) UITableView *tableV;
@property (strong, nonatomic) NSMutableArray *dataSource;
@end

@implementation FirstViewController
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    if(self.state < 2){
        self.navigationController.navigationBarHidden = YES;
    }
    [UIApplication sharedApplication].applicationIconBadgeNumber =  [[RCIMClient sharedRCIMClient] getTotalUnreadCount];
    
    UITabBarItem *item = [self.tabBarController.tabBar.items objectAtIndex:1];
    if([[RCIMClient sharedRCIMClient] getTotalUnreadCount]> 0){
        
        item.badgeValue = [NSString stringWithFormat:@"%@",@([[RCIMClient sharedRCIMClient] getTotalUnreadCount])];
        if (@available(iOS 10.0, *)) {
            item.badgeColor = kAppColor;
        } else {
            // Fallback on earlier versions
            
        }
    }
    else
    {
        item.badgeValue = [NSString stringWithFormat:@"%@",@""];
        if (@available(iOS 10.0, *)) {
            item.badgeColor = [UIColor clearColor];
        } else {
            // Fallback on earlier versions
        }
    }
    if (self.state == HomePageState) {
        [self getHomePageList];
    }
    if (self.state == GroupDetailState) {
        [self getGroupDetail];
    }
    if (self.state == EventDetailState) {
        [self getEventDetail];
    }
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
    [self refreshStop];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.dataSource = [NSMutableArray array];
    descriptionWidth = self.view.width - self.view.width/5 - 5 - 15;
    
    if (@available(iOS 11.0, *)) {
        self.tableV.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    self.view.backgroundColor = kBgColor;
    [InternationalControl initUserLanguage];//初始化应用语言
    
    bundle = [InternationalControl bundle];
    [self SetupNav];
    [self TableView];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushFirst:)name:kPushName_FirstVc object:nil];

//   [self performSelector:@selector(methodName) withObject:self afterDelay:1];
    
    // Do any additional setup after loading the view.
}

- (void)getHomePageList {
    if ([UserInfomation shareManager].pk == nil) {
        return;
    }
    [self refreshBegin];
    [self.dataSource removeAllObjects];
    NSDictionary *parameters = @{
                                 @"pk":[UserInfomation shareManager].pk
                                 };
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kHomePageList];
    NSLog(@"urlStr:%@",urlStr);
    [DataContrller PostRequestUrl:urlStr Param:parameters requestSuccess:^(NSDictionary *backDic) {
        [self refreshStop];
        NSLog(@"backDic:%@",backDic);
        if ([backDic[@"returnCode"] integerValue] == 200) {
            HomePageModel *model = [[HomePageModel alloc] initWithDictionary:backDic[@"obj"] error:nil];
            NSLog(@"model --- %@", model);
            for (CustomerModel *customerModel in model.customers) {
                [self.dataSource addObject:customerModel];
            }
            for (GroupModel *groupModel in model.groups) {
                [self.dataSource addObject:groupModel];
            }
            for (EventModel *eventModel in model.events) {
                [self.dataSource addObject:eventModel];
            }
            [self.tableV reloadData];
        } else {
            [self showAlert:backDic[@"msg"]];
        }
    } requestFail:^(NSString *backErrorStr) {
        [self refreshStop];
        NSLog(@"backErrorStr:%@",backErrorStr);
        [self showAlert:backErrorStr];
    }];
}

- (void)getGroupDetail {
    if ([UserInfomation shareManager].pk == nil) {
        return;
    }
    [self refreshBegin];
    [self.dataSource removeAllObjects];
    NSDictionary *parameters = @{
                                 @"pk1":self._id,
                                 @"pk2":[UserInfomation shareManager].pk
                                 };
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kGroupDetail];
    NSLog(@"urlStr:%@",urlStr);
    [DataContrller PostRequestUrl:urlStr Param:parameters requestSuccess:^(NSDictionary *backDic) {
        [self refreshStop];
        NSLog(@"backDic:%@",backDic);
        [self.dataSource removeAllObjects];
        if ([backDic[@"returnCode"] integerValue] == 200) {
            GroupModel *groupModel = [[GroupModel alloc] initWithDictionary:backDic[@"obj"] error:nil];
            [self.dataSource addObject:groupModel];
        } else {
            [self showAlert:backDic[@"msg"]];
        }
        [self.tableV reloadData];
    } requestFail:^(NSString *backErrorStr) {
        [self refreshStop];
        NSLog(@"backErrorStr:%@",backErrorStr);
        [self showAlert:backErrorStr];
    }];
}

- (void)getEventDetail {
    if ([UserInfomation shareManager].pk == nil) {
        return;
    }
    [self refreshBegin];
    [self.dataSource removeAllObjects];
    NSDictionary *parameters = @{
                                 @"pk1":@"1",
                                 @"pk2":[UserInfomation shareManager].pk
                                 };
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kEventDetail];
    NSLog(@"urlStr:%@",urlStr);
    [DataContrller PostRequestUrl:urlStr Param:parameters requestSuccess:^(NSDictionary *backDic) {
        [self refreshStop];
        NSLog(@"backDic:%@",backDic);
        [self.dataSource removeAllObjects];
        if ([backDic[@"returnCode"] integerValue] == 200) {
            EventModel *eventModel = [[EventModel alloc] initWithDictionary:backDic[@"obj"] error:nil];
            [self.dataSource addObject:eventModel];
        } else {
            [self showAlert:backDic[@"msg"]];
        }
        [self.tableV reloadData];
    } requestFail:^(NSString *backErrorStr) {
        [self refreshStop];
        NSLog(@"backErrorStr:%@",backErrorStr);
        [self showAlert:backErrorStr];
    }];
}

-(void)pushFirst:(NSNotification *)notif
{
    NSLog(@"notif:%@",notif);
    NSDictionary *dic = notif.userInfo;
    
    NSLog(@"dic:%@",dic[@"aps"]);
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kPushName_FirstVc object:self];
}
//- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
//{
//    [self.navigationController popToRootViewControllerAnimated:NO];
//    return YES;
//}
-(void)SetupNav
{
    if(self.state < 2){
        self.headView = [[FirHeadView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kNaviHeight)];
        [self.view addSubview:self.headView];
    }
    else{
        self.headView = [[FirHeadView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 0)];
    }
}
-(void)TableView
{
    self.tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, self.headView.height, self.view.width-10, self.view.height-self.headView.height-50)];//指定位置大小
    self.tableV.center = CGPointMake(self.view.width/2, self.headView.height+self.tableV.height/2);
    self.tableV.backgroundColor = [UIColor clearColor];
    [self.tableV setDelegate:self];//指定委托
    [self.tableV setDataSource:self];//指定数据委托
    self.tableV.estimatedRowHeight = 0;
    self.tableV.estimatedSectionHeaderHeight = 0;
    self.tableV.estimatedSectionFooterHeight = 0;
    self.tableV.layer.masksToBounds = YES;
    self.tableV.layer.cornerRadius = 10;
    self.tableV.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableV];//加载tableview

}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
    //    if (!cell) {
    //        cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"TableViewCell"];
    //
    //    }
    static NSString *CellIdentifier = @"TableViewCell";
    // 通过indexPath创建cell实例 每一个cell都是单独的
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    // 判断为空进行初始化  --（当拉动页面显示超过主页面内容的时候就会重用之前的cell，而不会再次初始化）
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.layer.masksToBounds = YES;
        cell.layer.cornerRadius = 10;
        cell.width = tableView.width;
    }
    NSMutableArray *imageViews = [[NSMutableArray alloc]init];
    
    id model = self.dataSource[indexPath.row];
    NSInteger type;
    NSString *titleName;
    NSString *userName;
    if ([model isKindOfClass:CustomerModel.class]) {
        type = 0;
        CustomerModel *custmerModel = model;
        for (NSString *picurl in custmerModel.picUrl) {
            [imageViews addObject:picurl];
        }
        titleName = custmerModel.userName;
        userName = [NSString stringWithFormat:@"%ld · %@ · %ld", custmerModel.age, custmerModel.location,  custmerModel.height];
    } else if ([model isKindOfClass:GroupModel.class]) {
        type = 1;
        GroupModel *groupModel = model;
        if (groupModel.picUrl != nil) {
            [imageViews addObject:groupModel.picUrl];
        }
        if (groupModel.joined == YES) {
            titleName = [bundle localizedStringForKey:@"havejoin" value:nil table:@"hello"];
        } else {
           titleName = [bundle localizedStringForKey:@"wannajoin" value:nil table:@"hello"];
        }
        userName = groupModel.name;
    } else {
        type = 2;
        EventModel *eventModel = model;
        if (eventModel.picUrl != nil) {
            [imageViews addObject:eventModel.picUrl];
        }
        if (eventModel.joined == YES) {
            titleName = [bundle localizedStringForKey:@"havejoin" value:nil table:@"hello"];
        } else {
            titleName = [bundle localizedStringForKey:@"wannajoin" value:nil table:@"hello"];
        }
        userName = eventModel.createdTime;
    }
    if (imageViews.count == 0) {
        [imageViews addObject:@"1"];
    }
    JKBannarView *bannerView = [[JKBannarView alloc]initWithFrame:CGRectMake(0, 0, kBannerHeight, kBannerHeight) viewSize:CGSizeMake(kBannerHeight,kBannerHeight)];
    bannerView.tag = 100;
    bannerView.center = CGPointMake(cell.width/2, kBannerTopSpace+bannerView.height/2);
    bannerView.items = imageViews;
    bannerView.layer.masksToBounds = YES;
    bannerView.layer.cornerRadius = 10;
    [cell addSubview:bannerView];
    
    [bannerView imageViewClick:^(JKBannarView * _Nonnull barnerview, NSInteger index) {
        if (barnerview.tag == 100) {
            [self lookBigImage:imageViews];
        }
        NSLog(@"点击图片%ld",index);
    }];
    
    UILabel *userNameLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/2, kUserNameLabeHeight)];
    userNameLab.center = CGPointMake(cell.width/2, bannerView.y+bannerView.height+userNameLab.height / 2);
//    userNameLab.backgroundColor = [UIColor redColor];
    userNameLab.textAlignment = NSTextAlignmentCenter;
    userNameLab.adjustsFontSizeToFitWidth = YES;
    [cell addSubview:userNameLab];
    userNameLab.text = titleName;
    userNameLab.font=[UIFont fontWithName:kFontName size:userNameLab.height*0.8];
    
    UILabel *UserInfolab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, cell.width/2, kUserInfoLabeHeight)];
    UserInfolab.center = CGPointMake(cell.width/2, userNameLab.y+userNameLab.height+UserInfolab.height / 2);
//    UserInfolab.backgroundColor = [UIColor yellowColor];
    UserInfolab.textAlignment = NSTextAlignmentCenter;
    UserInfolab.adjustsFontSizeToFitWidth = YES;
    [cell addSubview:UserInfolab];
    UserInfolab.text = userName;
    UserInfolab.font = [UIFont fontWithName:kFontName size:UserInfolab.height*0.5];
    
    UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kCellBtnHeight, kCellBtnHeight)];
    leftBtn.center = CGPointMake(5+leftBtn.width/2, bannerView.y+bannerView.height+leftBtn.height/2+kBannerTopSpace);
//    leftBtn.backgroundColor = [UIColor redColor];
    [leftBtn setImage:[UIImage imageNamed:@"cellCancel"] forState:UIControlStateNormal];
    leftBtn.tag = 200 + indexPath.row;
    objc_setAssociatedObject(leftBtn,"targetId", model, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    [leftBtn addTarget:self action:@selector(unlikeAction:) forControlEvents:UIControlEventTouchDown];
    [cell addSubview:leftBtn];
    
    float titleLabW = cell.width/5-5;
    UIButton *rightBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, kCellBtnHeight, kCellBtnHeight)];
    rightBtn.center = CGPointMake(cell.width-rightBtn.width/2-5, bannerView.y+bannerView.height+rightBtn.height/2+kBannerTopSpace);
//    rightBtn.backgroundColor = [UIColor greenColor];
    [rightBtn setImage:[UIImage imageNamed:@"cellshouchang"] forState:UIControlStateNormal];
    rightBtn.tag = indexPath.row;
    objc_setAssociatedObject(rightBtn,"targetId", model, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    [cell addSubview:rightBtn];
    
    //custom
    if(type == 0)
    {
        CustomerModel *custmerModel = model;
        //left button and right button Stats
        if (custmerModel.currentStatus == 0) {
            //
            leftBtn.hidden = NO;
            rightBtn.userInteractionEnabled = YES;
            [rightBtn addTarget:self action:@selector(likeAction:) forControlEvents:UIControlEventTouchUpInside];
        } else if (custmerModel.currentStatus == 1) {
            leftBtn.hidden = YES;
            [rightBtn setImage:[UIImage imageNamed:@"povermove_1"] forState:UIControlStateNormal];
            rightBtn.userInteractionEnabled = YES;
            [rightBtn addTarget:self action:@selector(likeAction:) forControlEvents:UIControlEventTouchUpInside];
        } else if (custmerModel.currentStatus == 2) {
            leftBtn.hidden = NO;
            [leftBtn setImage:[UIImage imageNamed:@"unlike"] forState:UIControlStateNormal];
            rightBtn.hidden = YES;
        } else if (custmerModel.currentStatus == 3) {
            leftBtn.hidden = YES;
            [rightBtn setImage:[UIImage imageNamed:@"povermove_2"] forState:UIControlStateNormal];
            rightBtn.userInteractionEnabled = NO;
        }
        
        UILabel *aboutMeTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, UserInfolab.y+UserInfolab.height+kBannerTopSpace, titleLabW, kCellTitleLabHeight)];
        //    aboutMeTitleLab.backgroundColor = [UIColor redColor];
        //    aboutMeTitleLab.font = [UIFont systemFontOfSize:kFontSize];
        aboutMeTitleLab.text = [bundle localizedStringForKey:@"AboutMe" value:nil table:@"hello"];
        aboutMeTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        aboutMeTitleLab.textColor = titleFontColor;
        aboutMeTitleLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:aboutMeTitleLab];
        
        float aboutMelabHeight =[self calculateRowHeight:custmerModel.about fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:custmerModel.about fontSize:kFontSize]:kCellTitleLabHeight;
        UILabel *aboutMeInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeTitleLab.x+aboutMeTitleLab.width+10, UserInfolab.y+UserInfolab.height+kBannerTopSpace, cell.width-aboutMeTitleLab.width-15, aboutMelabHeight)];
        aboutMeInfoLab.numberOfLines = 0;
        aboutMeInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
        //    aboutMeInfoLab.font = [UIFont systemFontOfSize:kFontSize];
        aboutMeInfoLab.text = custmerModel.about;
        [cell addSubview:aboutMeInfoLab];
        
        UILabel *EducationTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, aboutMeInfoLab.y+aboutMeInfoLab.height, titleLabW, kCellTitleLabHeight)];
        //    EducationTitleLab.backgroundColor = [UIColor redColor];
        EducationTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        EducationTitleLab.text = [bundle localizedStringForKey:@"Education" value:nil table:@"hello"];
        EducationTitleLab.textColor = titleFontColor;
        EducationTitleLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:EducationTitleLab];
        
        float educationlabHeight = [self calculateRowHeight:custmerModel.education fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:custmerModel.education fontSize:kFontSize]:kCellTitleLabHeight;
        UILabel *educationInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeInfoLab.x, aboutMeInfoLab.y+aboutMeInfoLab.height, aboutMeInfoLab.width, educationlabHeight)];
        educationInfoLab.numberOfLines = 0;
        educationInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
        educationInfoLab.text = custmerModel.education;
        [cell addSubview:educationInfoLab];
        
        UILabel *professionTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, educationInfoLab.y+educationInfoLab.height, titleLabW, kCellTitleLabHeight)];
        //    professionTitleLab.backgroundColor = [UIColor redColor];
        professionTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        professionTitleLab.text = [bundle localizedStringForKey:@"Profession" value:nil table:@"hello"];
        professionTitleLab.textColor = titleFontColor;
        professionTitleLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:professionTitleLab];
        
        float professionlabHeight = [self calculateRowHeight:custmerModel.profession fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:custmerModel.profession fontSize:kFontSize]:kCellTitleLabHeight;
        UILabel *professionInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeInfoLab.x, educationInfoLab.y+educationInfoLab.height, aboutMeInfoLab.width, professionlabHeight)];
        professionInfoLab.numberOfLines = 0;
        professionInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
        professionInfoLab.text = custmerModel.profession;
        [cell addSubview:professionInfoLab];
        
        
        UILabel *interestsTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, professionInfoLab.y+professionInfoLab.height, titleLabW, kCellTitleLabHeight)];
        //    interestsTitleLab.backgroundColor = [UIColor redColor];
        interestsTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        interestsTitleLab.text = [bundle localizedStringForKey:@"Interests" value:nil table:@"hello"];
        interestsTitleLab.textColor = titleFontColor;
        interestsTitleLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:interestsTitleLab];
        
        float interestslabHeight = [self calculateRowHeight:custmerModel.interests fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:custmerModel.interests fontSize:kFontSize]:kCellTitleLabHeight;
        UILabel *interestsInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeInfoLab.x, professionInfoLab.y+professionInfoLab.height, aboutMeInfoLab.width, interestslabHeight)];
        interestsInfoLab.numberOfLines = 0;
        interestsInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
        interestsInfoLab.text = custmerModel.interests;
        //    interestsInfoLab.textColor = titleFontColor;
        [cell addSubview:interestsInfoLab];
        
        UILabel *interestedTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, interestsInfoLab.y+interestsInfoLab.height, titleLabW, kCellTitleLabHeight)];
        //    interestedTitleLab.backgroundColor = [UIColor redColor];
        interestedTitleLab.font = [UIFont fontWithName:kFontName size:kTitleFontSize];
        interestedTitleLab.text = [bundle localizedStringForKey:@"Interested" value:nil table:@"hello"];
        interestedTitleLab.textColor = titleFontColor;
        interestedTitleLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:interestedTitleLab];
        
        float interestedlabHeight = [self calculateRowHeight:[NSString stringWithFormat:@"%@%@",custmerModel.interests,@".More"] fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:[NSString stringWithFormat:@"%@%@",custmerModel.interests,@".More"] fontSize:kFontSize]:kCellTitleLabHeight;
        UILabel *interestedInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeInfoLab.x, interestsInfoLab.y+interestsInfoLab.height, aboutMeInfoLab.width, interestedlabHeight)];
        interestedInfoLab.numberOfLines = 0;
        interestedInfoLab.tag = indexPath.row;
//        interestedInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
        if (custmerModel.interested.length == 0) {
            interestedInfoLab.text = @"";
        } else {
            interestedInfoLab.text = [NSString stringWithFormat:@"%@%@", custmerModel.interested ,@".More"];
        }
        [cell addSubview:interestedInfoLab];
        if (custmerModel.interested.length > 0) {
        NSMutableAttributedString *interestedInfoLabattributedString = [[NSMutableAttributedString alloc]initWithString:interestedInfoLab.text];
         [interestedInfoLabattributedString addAttribute:NSForegroundColorAttributeName value:kTouchTitleColor range:NSMakeRange(interestedInfoLab.text.length-5,5)];
         [interestedInfoLabattributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:kFontName size:kFontSize] range:NSMakeRange(0, interestedInfoLab.text.length)];
        interestedInfoLab.attributedText = interestedInfoLabattributedString;
        [interestedInfoLab yb_addAttributeTapActionWithStrings:@[@".More"] tapClicked:^(NSString *string, NSRange range, NSInteger index) {
                NSLog(@"%@",string);
                EventGroupListViewController *egList = [[EventGroupListViewController alloc] init];
                egList.titleStr = @"Event/Group";
                [self.navigationController pushViewController:egList animated:YES];
            }];
        }
//        interestedInfoLab.enabledTapEffect = NO;
        
        UILabel *GroupsTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, interestedInfoLab.y+interestedInfoLab.height, titleLabW, kCellTitleLabHeight)];
        //    GroupsTitleLab.backgroundColor = [UIColor redColor];
        GroupsTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        GroupsTitleLab.text = [bundle localizedStringForKey:@"Groups" value:nil table:@"hello"];
        GroupsTitleLab.textColor = titleFontColor;
        GroupsTitleLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:GroupsTitleLab];
        
        float GroupslabHeight = [self calculateRowHeight:[NSString stringWithFormat:@"%@%@",custmerModel.groups,@".More"] fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:[NSString stringWithFormat:@"%@%@",custmerModel.groups,@".More"] fontSize:kFontSize]:kCellTitleLabHeight;
        UILabel *GroupsInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeInfoLab.x, interestedInfoLab.y+interestedInfoLab.height, aboutMeInfoLab.width, GroupslabHeight)];
        GroupsInfoLab.numberOfLines = 0;
        GroupsInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
        if (custmerModel.groups.length == 0) {
            GroupsInfoLab.text = @"";
        } else {
            GroupsInfoLab.text = [NSString stringWithFormat:@"%@%@",custmerModel.groups,@".More"];
        }
        [cell addSubview:GroupsInfoLab];
        if (custmerModel.groups.length > 0) {
        NSMutableAttributedString *GroupsInfoLabattributedString = [[NSMutableAttributedString alloc]initWithString:GroupsInfoLab.text];
        [GroupsInfoLabattributedString addAttribute:NSForegroundColorAttributeName value:kTouchTitleColor range:NSMakeRange(GroupsInfoLab.text.length-5,5)];
        [GroupsInfoLabattributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:kFontName size:kFontSize] range:NSMakeRange(0, GroupsInfoLab.text.length)];
        GroupsInfoLab.attributedText = GroupsInfoLabattributedString;
            [GroupsInfoLab yb_addAttributeTapActionWithStrings:@[@".More"] tapClicked:^(NSString *string, NSRange range, NSInteger index) {
                NSLog(@"%@",string);
                EventGroupListViewController *egList = [[EventGroupListViewController alloc] init];
                egList.titleStr = @"Event/Group";
                [self.navigationController pushViewController:egList animated:YES];
            }];
        }
        
        UILabel *religionTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, GroupsInfoLab.y+GroupsInfoLab.height, titleLabW, kCellTitleLabHeight)];
        //    religionTitleLab.backgroundColor = [UIColor redColor];
        religionTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        religionTitleLab.text = [bundle localizedStringForKey:@"Religion" value:nil table:@"hello"];
        religionTitleLab.textColor = titleFontColor;
        religionTitleLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:religionTitleLab];
        
        float religionlabHeight = [self calculateRowHeight:custmerModel.religion fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:custmerModel.religion fontSize:kFontSize]:kCellTitleLabHeight;
        UILabel *religionInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeInfoLab.x, GroupsInfoLab.y+GroupsInfoLab.height, aboutMeInfoLab.width, religionlabHeight)];
        religionInfoLab.numberOfLines = 0;
        religionInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
        religionInfoLab.text = custmerModel.religion;
        [cell addSubview:religionInfoLab];
    }
    //group：
    else if (type == 1)
    {
        GroupModel *groupModel = model;
        //left button and right button Stats
        if (groupModel.joined == YES) {
            //已加入
            leftBtn.hidden = YES;
            rightBtn.hidden = YES;
        } else {
            //未加入
            leftBtn.hidden = YES;
            [rightBtn addTarget:self action:@selector(joinAction:) forControlEvents:UIControlEventTouchUpInside];
        }
        if (self.state == GroupDetailState) {
            rightBtn.hidden = YES;
        }
        UILabel *aboutMeTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, UserInfolab.y+UserInfolab.height+kBannerTopSpace, titleLabW, kCellTitleLabHeight)];
        //    aboutMeTitleLab.backgroundColor = [UIColor redColor];
        //    aboutMeTitleLab.font = [UIFont systemFontOfSize:kFontSize];
        aboutMeTitleLab.text = [bundle localizedStringForKey:@"AboutMe" value:nil table:@"hello"];
        aboutMeTitleLab.font = [UIFont fontWithName:kFontName size:kTitleFontSize];
        aboutMeTitleLab.textColor = titleFontColor;
        aboutMeTitleLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:aboutMeTitleLab];
        
        float aboutMelabHeight =[self calculateRowHeight:groupModel.about fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:groupModel.about fontSize:kFontSize]:kCellTitleLabHeight;
        UILabel *aboutMeInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeTitleLab.x+aboutMeTitleLab.width+10, UserInfolab.y+UserInfolab.height+kBannerTopSpace, cell.width-aboutMeTitleLab.width-15, aboutMelabHeight)];
        aboutMeInfoLab.numberOfLines = 0;
        aboutMeInfoLab.font = [UIFont fontWithName:kFontName size:kFontSize];
        //    aboutMeInfoLab.font = [UIFont systemFontOfSize:kFontSize];
        aboutMeInfoLab.text = groupModel.about;
        [cell addSubview:aboutMeInfoLab];
        
        UILabel *siezTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, aboutMeInfoLab.y+aboutMeInfoLab.height, titleLabW, kCellTitleLabHeight)];
        //    EducationTitleLab.backgroundColor = [UIColor redColor];
        siezTitleLab.font = [UIFont fontWithName:kFontName size:kTitleFontSize];
        siezTitleLab.text = [bundle localizedStringForKey:@"size" value:nil table:@"hello"];
        siezTitleLab.textColor = titleFontColor;
        siezTitleLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:siezTitleLab];
        
        NSString *sizeStr = [NSString stringWithFormat:@"%@ %@ · %@ %@",groupModel.size, [bundle localizedStringForKey:@"members" value:nil table:@"hello"],groupModel.friendCount, [bundle localizedStringForKey:@"imFriends" value:nil table:@"hello"]];
        float sizeHeight = [self calculateRowHeight:sizeStr fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:sizeStr fontSize:kFontSize]:kCellTitleLabHeight;
        
        UILabel *sizeInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(aboutMeInfoLab.x, aboutMeInfoLab.y+aboutMeInfoLab.height, aboutMeInfoLab.width, sizeHeight)];
        sizeInfoLab.numberOfLines = 0;
        sizeInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
        sizeInfoLab.text = sizeStr;
        [cell addSubview:sizeInfoLab];
        
        NSMutableAttributedString *sizeInfoLabattributedString = [[NSMutableAttributedString alloc]initWithString:sizeInfoLab.text];
        [sizeInfoLabattributedString addAttribute:NSForegroundColorAttributeName value:kTouchTitleColor range:NSMakeRange(sizeInfoLab.text.length-sizeStr.length,sizeStr.length)];
        [sizeInfoLabattributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:kFontName size:kFontSize] range:NSMakeRange(0, sizeInfoLab.text.length)];
        sizeInfoLab.attributedText = sizeInfoLabattributedString;
        [sizeInfoLab yb_addAttributeTapActionWithStrings:@[sizeInfoLab.text] tapClicked:^(NSString *string, NSRange range, NSInteger index) {
            NSLog(@"Size:%@",string);
//            EventGroupListViewController *egList = [[EventGroupListViewController alloc] init];
//            egList.titleStr = @"Event/Group";
//            [self.navigationController pushViewController:egList animated:YES];
            
            MemberListViewController *VC = [[MemberListViewController alloc] init];
            NSMutableDictionary *params = [NSMutableDictionary dictionary];
            params[@"pk"] = groupModel.pk;
            params[@"customerId"] = [UserInfomation shareManager].pk;
            VC.params = params;
            VC.apiStr = @"/customer/getGroupMember";
//            VC.apiStr = @"/customer/getEventMember";
            //    VC.apiStr = @"/customer/matchInGroup";
            VC.title = @"Member in Group";
            [self.navigationController pushViewController:VC animated:YES];
        }];
        
//        float matchInGroupLabHeight =[self calculateRowHeight:@"Matches In Group" fontSize:kFontSize];
        
        NSString *lan = [InternationalControl userLanguage];
        NSString *groupStr ;
        if([lan isEqualToString:@"en"]){//判断当前的语言，进行改变
            groupStr = @"Matches \nIn Group";
        }else{
            groupStr = @"匹配\n组";
        }
        UILabel *matchInGroupLab = [[UILabel alloc] initWithFrame:CGRectMake(0, sizeInfoLab.y+sizeInfoLab.height, titleLabW, kCellGroupTitleLabHeight)];
        //    religionTitleLab.backgroundColor = [UIColor redColor];
        matchInGroupLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        matchInGroupLab.text = groupStr;
        matchInGroupLab.textColor = titleFontColor;
        matchInGroupLab.numberOfLines = 0;
        matchInGroupLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:matchInGroupLab];
        
        NSInteger number;
        if (groupModel.matchesInGroupCustomerList.count >= 3) {
            number = 3;
        } else {
            number = groupModel.matchesInGroupCustomerList.count;
        }
        
        for (int i= 0 ; i< number; i++) {
            NSInteger space = 10;
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(sizeInfoLab.x, matchInGroupLab.y+kCellGroupTitleLabHeight*i, aboutMeInfoLab.width, kCellGroupTitleLabHeight)];
//            view.backgroundColor = [UIColor redColor];
            [cell addSubview:view];
            
            UIImageView *headImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, view.height*0.8, view.height*0.8)];
            headImageV.center = CGPointMake(headImageV.width/2, view.height/2);
            headImageV.layer.masksToBounds = YES;
            headImageV.layer.cornerRadius = headImageV.height/2;
//            headImageV.backgroundColor = [UIColor yellowColor];
            [view addSubview:headImageV];
            NSDictionary *dic = groupModel.matchesInGroupCustomerList[i];
            [headImageV sd_setImageWithURL:[NSURL URLWithString:dic[@"picUrl"]] placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
            
            UILabel *nameLab = [[UILabel alloc] initWithFrame:CGRectMake(headImageV.x+headImageV.width+space, 0, view.width-space-headImageV.width, view.height)];
//            nameLab.backgroundColor = [UIColor blueColor];
            nameLab.font = [UIFont fontWithName:kFontName size:kFontSize];
            nameLab.text = dic[@"username"];
            [view addSubview:nameLab];
        }
        
        if (number >= 3) {
            UIButton *seeAllButton = [UIButton buttonWithType:UIButtonTypeCustom];
            seeAllButton.frame = CGRectMake(sizeInfoLab.x, matchInGroupLab.y+kCellGroupTitleLabHeight*number, aboutMeInfoLab.width, kCellGroupTitleLabHeight);
            seeAllButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
            NSString *seeAllString = [NSString stringWithFormat:@"%@·%ld", [bundle localizedStringForKey:@"seeAll" value:nil table:@"hello"],  groupModel.matchesInGroupCustomerList.count];
            [seeAllButton setTitle:seeAllString forState:UIControlStateNormal];
            [seeAllButton setTitleColor:kTouchTitleColor forState:UIControlStateNormal];
            seeAllButton.titleLabel.font = [UIFont systemFontOfSize:kFontSize];
            objc_setAssociatedObject(seeAllButton,"seeAll", groupModel, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
            [seeAllButton addTarget:self action:@selector(seeAllAction:) forControlEvents:UIControlEventTouchUpInside];
            [cell addSubview:seeAllButton];
        }
    }
    //event
    else if (type == 2)
    {
        EventModel *event = model;
        //left button and right button Stats
        if (event.joined == YES) {
            //已加入
            leftBtn.hidden = YES;
            rightBtn.hidden = YES;
        } else {
            //未加入
            leftBtn.hidden = YES;
            [rightBtn addTarget:self action:@selector(joinAction:) forControlEvents:UIControlEventTouchUpInside];
        }
        if (self.state == EventDetailState) {
            rightBtn.hidden = YES;
        }
        UILabel *nameTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, UserInfolab.y+UserInfolab.height+kBannerTopSpace, titleLabW, kCellTitleLabHeight)];
        //    aboutMeTitleLab.backgroundColor = [UIColor redColor];
        //    aboutMeTitleLab.font = [UIFont systemFontOfSize:kFontSize];
        nameTitleLab.text = [bundle localizedStringForKey:@"Name" value:nil table:@"hello"];
        nameTitleLab.font = [UIFont fontWithName:kFontName size:kTitleFontSize];
        nameTitleLab.textColor = titleFontColor;
        nameTitleLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:nameTitleLab];
        
        float nameInfolabHeight = [self calculateRowHeight:event.name fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:event.name fontSize:kFontSize]:kCellTitleLabHeight;
        UILabel *nameInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(nameTitleLab.x+nameTitleLab.width+10, UserInfolab.y+UserInfolab.height+kBannerTopSpace, cell.width-nameTitleLab.width-15, nameInfolabHeight)];
        NSLog(@"width  ----  %lf", cell.width-nameTitleLab.width-15);
        nameInfoLab.numberOfLines = 0;
        nameInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
        //    aboutMeInfoLab.font = [UIFont systemFontOfSize:kFontSize];
        nameInfoLab.text = event.name;
        [cell addSubview:nameInfoLab];
        
        UILabel *addressTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, nameInfoLab.y + nameInfoLab.height, titleLabW, kCellTitleLabHeight)];
        //    EducationTitleLab.backgroundColor = [UIColor redColor];
        addressTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        addressTitleLab.text = [bundle localizedStringForKey:@"address" value:nil table:@"hello"];
        addressTitleLab.textColor = titleFontColor;
        addressTitleLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:addressTitleLab];
        
        float addresslabHeight = [self calculateRowHeight:event.address fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:event.address fontSize:kFontSize]:kCellTitleLabHeight;
        UILabel *addressInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(nameInfoLab.x, nameInfoLab.y+nameInfoLab.height, nameInfoLab.width, addresslabHeight)];
        addressInfoLab.numberOfLines = 0;
        addressInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
        addressInfoLab.text = event.address;
        [cell addSubview:addressInfoLab];
        
        UILabel *interestedLab = [[UILabel alloc] initWithFrame:CGRectMake(0, addressInfoLab.y+addressInfoLab.height, titleLabW, kCellTitleLabHeight)];
        //    EducationTitleLab.backgroundColor = [UIColor redColor];
        interestedLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        interestedLab.text = [bundle localizedStringForKey:@"Interested" value:nil table:@"hello"];
        interestedLab.textColor = titleFontColor;
        interestedLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:interestedLab];
        
        NSString *interestedStr = [NSString stringWithFormat:@"%@%@",event.interestedCount,@"Members"];
        float sizeHeight =[self calculateRowHeight:interestedStr fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:interestedStr fontSize:kFontSize]:kCellTitleLabHeight;
        
        UILabel *interestedInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(addressInfoLab.x, addressInfoLab.y+addressInfoLab.height, nameInfoLab.width, sizeHeight)];
        interestedInfoLab.numberOfLines = 0;
        interestedInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
        interestedInfoLab.text = interestedStr;
        [cell addSubview:interestedInfoLab];
        
        NSMutableAttributedString *interestedInfoLabattributedString = [[NSMutableAttributedString alloc]initWithString:interestedInfoLab.text];
        [interestedInfoLabattributedString addAttribute:NSForegroundColorAttributeName value:kTouchTitleColor range:NSMakeRange(interestedInfoLab.text.length-interestedStr.length,interestedStr.length)];
        [interestedInfoLabattributedString addAttribute:NSFontAttributeName value:[UIFont fontWithName:kFontName size:kFontSize] range:NSMakeRange(0, interestedInfoLab.text.length)];
        interestedInfoLab.attributedText = interestedInfoLabattributedString;
        [interestedInfoLab yb_addAttributeTapActionWithStrings:@[interestedInfoLab.text] tapClicked:^(NSString *string, NSRange range, NSInteger index) {
            NSLog(@"interested:%@",string);
//            EventGroupListViewController *egList = [[EventGroupListViewController alloc] init];
//            egList.titleStr = @"Event/Group";
//            [self.navigationController pushViewController:egList animated:YES];
            
            MemberListViewController *VC = [[MemberListViewController alloc] init];
            NSMutableDictionary *params = [NSMutableDictionary dictionary];
            params[@"pk"] = event.pk;
            params[@"customerId"] = [UserInfomation shareManager].pk;
            VC.params = params;
//            VC.apiStr = @"/customer/getGroupMember";
            VC.apiStr = @"/customer/getEventMember";
            //    VC.apiStr = @"/customer/matchInGroup";
            VC.title = @"Member in Group";
            [self.navigationController pushViewController:VC animated:YES];
        }];
        
        
        UILabel *DetailsTitleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, interestedInfoLab.y+interestedInfoLab.height, titleLabW, kCellTitleLabHeight)];
        //    religionTitleLab.backgroundColor = [UIColor redColor];
        DetailsTitleLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        DetailsTitleLab.text = [bundle localizedStringForKey:@"Details" value:nil table:@"hello"];
        DetailsTitleLab.textColor = titleFontColor;
        DetailsTitleLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:DetailsTitleLab];
        
        float detailslabHeight = [self calculateRowHeight:event.detail fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:event.detail fontSize:kFontSize]:kCellTitleLabHeight;
        UILabel *detailInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(nameInfoLab.x, interestedInfoLab.y+interestedInfoLab.height, nameInfoLab.width, detailslabHeight)];
        detailInfoLab.numberOfLines = 0;
        detailInfoLab.font=[UIFont fontWithName:kFontName size:kFontSize];
        detailInfoLab.text = event.detail;
        [cell addSubview:detailInfoLab];
        
        NSString *lan = [InternationalControl userLanguage];
        NSString *attendStr ;
        if([lan isEqualToString:@"en"]){//判断当前的语言，进行改变
            attendStr = @"Link";
        }else{
            attendStr = @"链接";
        }
        UILabel *attendLab = [[UILabel alloc] initWithFrame:CGRectMake(0, detailInfoLab.y+detailInfoLab.height, titleLabW, kCellTitleLabHeight)];
        //    religionTitleLab.backgroundColor = [UIColor redColor];
        attendLab.font=[UIFont fontWithName:kFontName size:kTitleFontSize];
        attendLab.text = attendStr;
        attendLab.textColor = titleFontColor;
        attendLab.numberOfLines = 0;
        attendLab.textAlignment = NSTextAlignmentRight;
        [cell addSubview:attendLab];
        
        float linklabHeight = [self calculateRowHeight:event.link fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:event.link fontSize:kFontSize]:kCellTitleLabHeight;
        UILabel *linkInfoLab = [[UILabel alloc] initWithFrame:CGRectMake(nameInfoLab.x, attendLab.y, nameInfoLab.width, linklabHeight)];
        linkInfoLab.numberOfLines = 0;
        linkInfoLab.font = [UIFont fontWithName:kFontName size:kFontSize];
        linkInfoLab.text = event.link;
        [cell addSubview:linkInfoLab];
        
        if (event.link.length > 0) {
            NSMutableAttributedString *linkInfoLabattributedString = [[NSMutableAttributedString alloc]initWithString:event.link];
            [linkInfoLabattributedString addAttribute:NSForegroundColorAttributeName value:kTouchTitleColor range:NSMakeRange(0 ,linkInfoLab.text.length)];
            linkInfoLab.attributedText = linkInfoLabattributedString;
            [linkInfoLab yb_addAttributeTapActionWithStrings:@[linkInfoLab.text] tapClicked:^(NSString *string, NSRange range, NSInteger index) {
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString:event.link]];
            }];
        }
        
        /*
        for (int i= 0 ; i< 3; i++) {
            NSInteger space = 10;
            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(detailInfoLab.x, attendLab.y+kCellGroupTitleLabHeight*i, detailInfoLab.width, kCellMatchesAttendTitleLabHeight)];
            //            view.backgroundColor = [UIColor redColor];
            [cell addSubview:view];
            
            UIImageView *headImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, view.height*0.8, view.height*0.8)];
            headImageV.center = CGPointMake(headImageV.width/2, view.height/2);
            headImageV.layer.masksToBounds = YES;
            headImageV.layer.cornerRadius = headImageV.height/2;
            //            headImageV.backgroundColor = [UIColor yellowColor];
            [view addSubview:headImageV];
            [headImageV sd_setImageWithURL:@"https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3001124303,1340309644&fm=27&gp=0.jpg"];
            
            UILabel *nameLab = [[UILabel alloc] initWithFrame:CGRectMake(headImageV.x+headImageV.width+space, 0, view.width-space-headImageV.width, view.height)];
            //            nameLab.backgroundColor = [UIColor blueColor];
            nameLab.font=[UIFont fontWithName:kFontName size:kFontSize];
            nameLab.text = @"Matt P.";
            [view addSubview:nameLab];
        }
        */
        
    }
    return cell;
    
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"row:%@ - section:%@",@(indexPath.row) , @(indexPath.section));
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    id model = self.dataSource[indexPath.row];
    NSInteger type;
    if ([model isKindOfClass:CustomerModel.class]) {
        type = 0;
    } else if ([model isKindOfClass:GroupModel.class]) {
        type = 1;
    } else {
        type = 2;
    }
    
    if(type == 0){
        
        CustomerModel *customerModel = model;
    float aboutMelabHeight = [self calculateRowHeight:customerModel.about fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:customerModel.about fontSize:kFontSize]:kCellTitleLabHeight;
    float educationlabHeight = [self calculateRowHeight:customerModel.education fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:customerModel.education fontSize:kFontSize]:kCellTitleLabHeight;
     float professionlabHeight = [self calculateRowHeight:customerModel.profession fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:customerModel.profession fontSize:kFontSize]:kCellTitleLabHeight;
    float interestslabHeight = [self calculateRowHeight:customerModel.interests fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:customerModel.interests fontSize:kFontSize]:kCellTitleLabHeight;
    float interestedlabHeight = [self calculateRowHeight:customerModel.interested fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:customerModel.interested fontSize:kFontSize]:kCellTitleLabHeight;
    float groupslabHeight = [self calculateRowHeight:customerModel.groups fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:customerModel.groups fontSize:kFontSize]:kCellTitleLabHeight;
    float religionlabHeight = [self calculateRowHeight:customerModel.religion fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:customerModel.religion fontSize:kFontSize]:kCellTitleLabHeight;
    
        return kBannerHeight + kBannerTopSpace+kBannerTopSpace+kUserNameLabeHeight+kUserInfoLabeHeight+aboutMelabHeight+educationlabHeight+professionlabHeight+interestslabHeight+interestedlabHeight+groupslabHeight+religionlabHeight;
    }
    else if(type == 1)
    {
        GroupModel *groupModel = model;
        float aboutMelabHeight = [self calculateRowHeight:groupModel.about fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:groupModel.about fontSize:kFontSize]:kCellTitleLabHeight;
        
         float sizeHeight =[self calculateRowHeight:@"1000 Member" fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:@"1000 Member" fontSize:kFontSize]:kCellTitleLabHeight;
        
        NSInteger count = groupModel.matchesInGroupCustomerList.count>3?3:groupModel.matchesInGroupCustomerList.count;
        float groupHeight = kCellGroupTitleLabHeight * count;
        
        float seeAllHeight;
        if (groupModel.matchesInGroupCustomerList.count > 3) {
            seeAllHeight = kCellGroupTitleLabHeight;
        } else {
            seeAllHeight = 0;
        }
        
        return kBannerHeight + kBannerTopSpace+kBannerTopSpace+kUserNameLabeHeight+kUserInfoLabeHeight+aboutMelabHeight+sizeHeight + groupHeight + seeAllHeight;
    }
    else if (type == 2)
    {
        EventModel *event = model;
        float nameLabHeight = [self calculateRowHeight:event.name fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:event.name fontSize:kFontSize]:kCellTitleLabHeight;
        
        float addressHeight = [self calculateRowHeight:event.address fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:event.address fontSize:kFontSize]:kCellTitleLabHeight;
        
        float interestedHeight =[self calculateRowHeight:event.interestedCount fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:event.interestedCount fontSize:kFontSize]:kCellTitleLabHeight;
        
        float detailslabHeight = [self calculateRowHeight:event.detail fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:event.detail fontSize:kFontSize]:kCellTitleLabHeight;
        
        float licklabHeight = [self calculateRowHeight:event.link fontSize:kFontSize]>kCellTitleLabHeight?[self calculateRowHeight:event.link fontSize:kFontSize]:kCellTitleLabHeight + 10;
       
        return kBannerHeight + kBannerTopSpace+kBannerTopSpace+kUserNameLabeHeight+kUserInfoLabeHeight+ nameLabHeight+addressHeight + interestedHeight + detailslabHeight+licklabHeight;
    }
    else
    {
        return 0;
    }
}
- (CGFloat)calculateRowHeight:(NSString *)string fontSize:(NSInteger)fontSize{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]};//指定字号
    CGRect rect = [string boundingRectWithSize:CGSizeMake(descriptionWidth, 0)/*计算高度要先指定宽度*/ options:NSStringDrawingUsesLineFragmentOrigin |
                   NSStringDrawingUsesFontLeading attributes:dic context:nil];
    return rect.size.height;
}

-(void)lookBigImage:(NSMutableArray *)imageArr
{
    
    UIView *bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
    bgview.backgroundColor = [UIColor blackColor];
    [[UIApplication sharedApplication].keyWindow addSubview:bgview];
    JKBannarView *bannerView = [[JKBannarView alloc]initWithFrame:CGRectMake(0, 0, kBannerHeight, kBannerHeight) viewSize:CGSizeMake(kBannerHeight,kBannerHeight)];
    bannerView.tag = 111;
    bannerView.center = CGPointMake(bgview.width/2, bgview.height/2);
    bannerView.items = imageArr;
    [bgview addSubview:bannerView];
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)];
    //设置点击次数和点击手指数
    tapGesture.numberOfTapsRequired = 1; //点击次数
    tapGesture.numberOfTouchesRequired = 1; //点击手指数
    [bgview addGestureRecognizer:tapGesture];
    
}
-(void)tapGesture:(UITapGestureRecognizer *)sender
{
    [sender.view removeFromSuperview];
    //轻击后要做的事情
}
-(void)leftBtn:(UIButton *)sender
{
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)likeAction:(UIButton *)sender {
    NSLog(@"%ld", sender.tag);
    NSInteger index = sender.tag;
    id first = objc_getAssociatedObject(sender, "targetId");
    CustomerModel *custmerModel = first;
    if (custmerModel.currentStatus == 1) {
        //power move 操作
        self.tabBarController.tabBar.hidden = YES;
        PowerMoveController *powerMove = [[PowerMoveController alloc] init];
        powerMove.model = custmerModel;
        powerMove.operationState = PowerMoveOperation;
        powerMove.powerMove = ^{
            custmerModel.currentStatus = 3;
            [self.dataSource replaceObjectAtIndex:index withObject:custmerModel];
            [self.tableV reloadData];
        };
        powerMove.retureBlock = ^{
            self.tabBarController.tabBar.hidden = NO;
        };
        powerMove.modalPresentationStyle = UIModalPresentationOverCurrentContext;
        powerMove.view.backgroundColor = [UIColor colorWithWhite:.0f alpha:0.9f];
        [self.navigationController presentViewController:powerMove animated:YES completion:nil];
        return;
    }
    [self likeRequestWithTargetId:first index:index];
}

- (void)unlikeAction:(UIButton *)sender {
    NSLog(@"%ld", sender.tag);
    NSInteger index = sender.tag - 200;
    id first = objc_getAssociatedObject(sender, "targetId");
    
    if ([first isKindOfClass:CustomerModel.class] ) {
        CustomerModel *custmerModel = first;
        if (custmerModel.currentStatus == 2) {
            //undo 操作
            self.tabBarController.tabBar.hidden = YES;
            PowerMoveController *powerMove = [[PowerMoveController alloc] init];
            powerMove.model = custmerModel;
            powerMove.operationState = UndoOperation;
            powerMove.powerMove = ^{
                custmerModel.currentStatus = 0;
                [self.dataSource replaceObjectAtIndex:index withObject:custmerModel];
                [self.tableV reloadData];
            };
            powerMove.retureBlock = ^{
                self.tabBarController.tabBar.hidden = NO;
            };
            powerMove.modalPresentationStyle = UIModalPresentationOverCurrentContext;
            powerMove.view.backgroundColor = [UIColor colorWithWhite:.0f alpha:0.9f];
            [self.navigationController presentViewController:powerMove animated:YES completion:nil];
            return;
        }
    };
    [self unlikeRequestWithTargetId:first index:index];
}

- (void)joinAction:(UIButton *)sender {
    NSLog(@"%ld", sender.tag);
    NSInteger index = sender.tag;
    NSString *first = objc_getAssociatedObject(sender, "targetId");
    [self jionRequestWithModel:first index:index];
}

- (void)seeAllAction:(UIButton *)sender {
    GroupModel *group = objc_getAssociatedObject(sender, "seeAll");
    MemberListViewController *VC = [[MemberListViewController alloc] init];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    params[@"pk"] = group.pk;
    params[@"customerId"] = [UserInfomation shareManager].pk;
    VC.params = params;
    VC.apiStr = @"/customer/matchInGroup";
    VC.title = @"Member in Group";
    [self.navigationController pushViewController:VC animated:YES];
}

- (void)likeRequestWithTargetId:(id)model index:(NSInteger)index {
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    NSInteger type;
    if ([model isKindOfClass:CustomerModel.class]) {
        type = 0;
        CustomerModel *custmerModel = model;
        if (custmerModel.pk != nil) {
            [parameters setObject:custmerModel.pk forKey:@"targetCustomerId"];
        }
        if (custmerModel.currentStatus == 0) {
            [parameters setObject:@(1) forKey:@"operate"];
        }
        if (custmerModel.currentStatus == 1) {
            [parameters setObject:@(3) forKey:@"operate"];
        }
    } else if ([model isKindOfClass:GroupModel.class]) {
        type = 1;
        GroupModel *groupModel = model;
        if (groupModel.pk != nil) {
            [parameters setObject:groupModel.pk forKey:@"targetCustomerId"];
        }
    } else {
        type = 2;
        EventModel *eventModel = model;
        if (eventModel.pk != nil) {
            [parameters setObject:eventModel.pk forKey:@"targetCustomerId"];
        }
    }
    if ([UserInfomation shareManager].pk != nil) {
        [parameters setObject:[UserInfomation shareManager].pk forKey:@"requestCustomerId"];
    }

    NSString *urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kHomeLike];
    NSLog(@"urlStr:%@",urlStr);
    [DataContrller PostRequestUrl:urlStr Param:parameters requestSuccess:^(NSDictionary *backDic) {
        NSLog(@"backDic:%@",backDic);
        if ([backDic[@"returnCode"] integerValue] == 200) {
            if (type == 0) {
                if ([backDic[@"obj"][@"nextOperate"] integerValue] != 4) {
                    CustomerModel *custmerModel = model;
                    if (custmerModel.currentStatus == 0) {
                        custmerModel.currentStatus = 1;
                    } else if (custmerModel.currentStatus == 1) {
                        custmerModel.currentStatus = 3;
                    }
                    [self.dataSource replaceObjectAtIndex:index withObject:custmerModel];
                } else {
                    [self.dataSource removeObjectAtIndex:index];
                }
            }
            [self.tableV reloadData];
        } else {
            [self showAlert:backDic[@"msg"]];
        }
    } requestFail:^(NSString *backErrorStr) {
        NSLog(@"backErrorStr:%@",backErrorStr);
        [self showAlert:backErrorStr];
        
    }];
}

- (void)unlikeRequestWithTargetId:(id)model index:(NSInteger)index {
    
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    NSInteger type;
    if ([model isKindOfClass:CustomerModel.class]) {
        type = 0;
        CustomerModel *custmerModel = model;
        if (custmerModel.pk != nil) {
            [parameters setObject:custmerModel.pk forKey:@"targetCustomerId"];
        }
        [parameters setObject:@(2) forKey:@"operate"];
    } else if ([model isKindOfClass:GroupModel.class]) {
        type = 1;
        GroupModel *groupModel = model;
        if (groupModel.pk != nil) {
            [parameters setObject:groupModel.pk forKey:@"targetCustomerId"];
        }
    } else {
        type = 2;
        EventModel *eventModel = model;
        if (eventModel.pk != nil) {
            [parameters setObject:eventModel.pk forKey:@"targetCustomerId"];
        }
    }
    if ([UserInfomation shareManager].pk != nil) {
        [parameters setObject:[UserInfomation shareManager].pk forKey:@"requestCustomerId"];
    }
    
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kHomeLike];
    NSLog(@"urlStr:%@",urlStr);
    [DataContrller PostRequestUrl:urlStr Param:parameters requestSuccess:^(NSDictionary *backDic) {
        [self refreshStop];
        NSLog(@"backDic:%@",backDic);
        if ([backDic[@"returnCode"] integerValue] == 200) {
            if (type == 0) {
                CustomerModel *custmerModel = model;
                if (custmerModel.currentStatus == 2) {
                    custmerModel.currentStatus = 0;
                } else {
                    custmerModel.currentStatus = 2;
                }
                [self.dataSource replaceObjectAtIndex:index withObject:custmerModel];
            }
            [self.tableV reloadData];
        } else {
            [self showAlert:backDic[@"msg"]];
        }
    } requestFail:^(NSString *backErrorStr) {
        NSLog(@"backErrorStr:%@",backErrorStr);
        [self showAlert:backErrorStr];
    }];
    
}

- (void)jionRequestWithModel:(id)model index:(NSInteger)index {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    NSInteger type;
    NSString *urlStr;
    
    if ([model isKindOfClass:GroupModel.class]) {
        type = 1;
        GroupModel *groupModel = model;
        if (groupModel.pk != nil) {
            [parameters setObject:groupModel.pk forKey:@"pk2"];
        }
        urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kHomeJoin];
    } else {
        type = 2;
        EventModel *eventModel = model;
        if (eventModel.pk != nil) {
            [parameters setObject:eventModel.pk forKey:@"pk2"];
        }
        urlStr = [NSString stringWithFormat:@"%@%@",kFirstUrl,kHomeJoinEvent];
    }
    if ([UserInfomation shareManager].pk != nil) {
        [parameters setObject:[UserInfomation shareManager].pk forKey:@"pk1"];
    }
    
    [DataContrller PostRequestUrl:urlStr Param:parameters requestSuccess:^(NSDictionary *backDic) {
        NSLog(@"backDic:%@",backDic);
        if ([backDic[@"returnCode"] integerValue] == 200) {
            if ([model isKindOfClass:GroupModel.class]) {
                GroupModel *groupModel = model;
                groupModel.joined = YES;
                [self.dataSource replaceObjectAtIndex:index withObject:groupModel];
            } else {
                EventModel *eventModel = model;
                eventModel.joined = YES;
                [self.dataSource replaceObjectAtIndex:index withObject:eventModel];
            }
            [self.tableV reloadData];
        } else {
            [self showAlert:backDic[@"msg"]];
        }
    } requestFail:^(NSString *backErrorStr) {
        NSLog(@"backErrorStr:%@",backErrorStr);
        [self showAlert:backErrorStr];
        
    }];
}

@end
